home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / board / UChessSrc.lha / ataksnew.h < prev    next >
Text File  |  1992-12-08  |  2KB  |  92 lines

  1. /*
  2.  * ataks.h - Header source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. inline static
  24. int
  25. SqAtakd2 (ARGSZ int sq, ARGSZ int side)
  26.  
  27. /*
  28.  * See if any piece with color 'side' ataks sq.  First check pawns then
  29.  * Queen, Bishop, Rook and King and last Knight.
  30.  */
  31.  
  32. {
  33.   register INTSIZE u;
  34.   register unsigned char *ppos, *pdir;
  35.   INTSIZE xside;
  36.  
  37.   xside = side ^ 1;
  38.   pdir = nextdir[ptype[xside][pawn]][sq];
  39.   u = pdir[sq];            /* follow captures thread */
  40.   if (u != sq)
  41.     {
  42.       if (board[u] == pawn && color[u] == side)
  43.     return (true);
  44.       u = pdir[u];
  45.       if (u != sq && board[u] == pawn && color[u] == side)
  46.     return (true);
  47.     }
  48.   /* king capture */
  49.   if (distance (sq, PieceList[side][0]) == 1)
  50.     return (true);
  51.   /* try a queen bishop capture */
  52.   ppos = nextpos[bishop][sq];
  53.   pdir = nextdir[bishop][sq];
  54.   u = ppos[sq];
  55.   do
  56.     {
  57.       if (color[u] == neutral)
  58.     u = ppos[u];
  59.       else
  60.     {
  61.       if (color[u] == side && (board[u] == queen || board[u] == bishop))
  62.         return (true);
  63.       u = pdir[u];
  64.     }
  65.   } while (u != sq);
  66.   /* try a queen rook capture */
  67.   ppos = nextpos[rook][sq];
  68.   pdir = nextdir[rook][sq];
  69.   u = ppos[sq];
  70.   do
  71.     {
  72.       if (color[u] == neutral)
  73.     u = ppos[u];
  74.       else
  75.     {
  76.       if (color[u] == side && (board[u] == queen || board[u] == rook))
  77.         return (true);
  78.       u = pdir[u];
  79.     }
  80.   } while (u != sq);
  81.   /* try a knight capture */
  82.   pdir = nextdir[knight][sq];
  83.   u = pdir[sq];
  84.   do
  85.     {
  86.       if (color[u] == side && board[u] == knight)
  87.     return (true);
  88.       u = pdir[u];
  89.   } while (u != sq);
  90.   return (false);
  91. }
  92.